import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created with IntelliJ IDEA.
 * User: Marcin
 * Date: 25.04.13
 * Time: 13:56
 * To change this template use File | Settings | File Templates.
 */
public class MainForm {
    private JPanel mainPanel;
    private JButton buttonReset;
    private JButton buttonResetPosition;
    private JSlider sliderLaserSize;
    private JSlider sliderParticleSize;
    private JSlider sliderMoveNoise;
    private JSlider sliderRotationNoise;
    private JSlider sliderLaserNoise;
    private JSlider sliderSigma;

    public MainForm() {
        super();
        buttonReset.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                sliderLaserSize.setValue(9);
                sliderParticleSize.setValue(1000);
                sliderMoveNoise.setValue(50);
                sliderRotationNoise.setValue(50);
                sliderLaserNoise.setValue(50);
                sliderSigma.setValue(50);
                WorldPanel.getInstance().reset();
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        buttonResetPosition.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                WorldPanel.getInstance().resetAgentMap(
                        sliderLaserSize.getValue(),
                        sliderParticleSize.getValue(),
                        sliderMoveNoise.getValue() / 100.0,
                        sliderRotationNoise.getValue() / 100.0,
                        sliderLaserNoise.getValue() / 100.0,
                        sliderSigma.getValue()
                );


                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderLaserSize.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setLaserSize(sliderLaserSize.getValue());
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderParticleSize.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setParticleSize(sliderParticleSize.getValue());
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });


        sliderMoveNoise.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setMoveNoiseParam(sliderMoveNoise.getValue() / 100.0);
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderRotationNoise.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setRotationNoiseParam(sliderRotationNoise.getValue() / 100.0);
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderLaserNoise.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setLaserNoiseParam(sliderLaserNoise.getValue() / 100.0);
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderSigma.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                WorldPanel.getInstance().setSigma(sliderSigma.getValue());
                WorldPanel.getInstance().repaint();
                WorldPanel.getInstance().addNotify();
            }
        });
        sliderParticleSize.setValue(1000);
    }

    public static void main(String[] args)  {


        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (InstantiationException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IllegalAccessException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        JFrame frame = new JFrame("MainForm");
            frame.setContentPane(new MainForm().mainPanel);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(WorldPanel.getInstance());

            frame.pack();
            frame.setVisible(true);





    }

}
